package cn.dust.design.pattern.creational.prototype.clone;

import cn.dust.design.pattern.creational.singleton.HungrySingleton;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Date;

/**
 * @Author: dust
 * @Date: 2019/11/26 17:10
 */
public class Test {

    public static void main(String[] args) throws CloneNotSupportedException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
//        Date birthday=new Date(0L);
//        Pig page=new Pig("佩奇",birthday);
//        Pig jozi= (Pig) page.clone();
//        System.out.println(page);
//        System.out.println(jozi);
//
//        page.getBirthday().setTime(412478613487L);
//        System.out.println(page);
//        System.out.println(jozi);

        HungrySingleton hungrySingleton=HungrySingleton.getInstance();
        Method method=hungrySingleton.getClass().getDeclaredMethod("clone");
        method.setAccessible(true);
        HungrySingleton cloneHungrySingleton= (HungrySingleton) method.invoke(hungrySingleton);
        System.out.println(hungrySingleton);
        System.out.println(cloneHungrySingleton);

    }
}
